/* ecstatus.i - --- INCLUDE FILE TO FIND THE STATUS OF PCR/PCO          */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*V8:ConvertMode=NoConvert                                              */
/* REVISION: 8.6      CREATED:  11/05/98   BY: *K1Y1* Felcy D'Souza     */
/* REVISION: 9.1      MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder     */
/* REVISION: 9.1      MODIFIED: 03/12/01   BY: *M120* Vihang Talwalkar  */
/* REVISION: 9.1      MODIFIED: 03/15/01   BY: *M100* Mark Christian    */

/*K1Y1*/ /* WHENEVER A PCR/PCO CHANGES THE STATUS (FROM UNSUBMITTED TO     */
     /* SUBMITTED, SUBMITTED TO APPROVED etc.), RESPECTIVE DATES ARE   */
     /* STORED IN ecm_mstr (SUBMITTED IN ecm_sub_date, APPROVED IN     */
     /* ecm_appr_date etc.). THIS PROCEDURE FINDS THE STATUS OF THE    */
     /* PCR/PCO BASED ON THE THE DATE STORED IN RESPECTIVE DATE FIELDS */
     /* IN A HIRARCHIAL WAY AND STORES IT IN l_ecm_status. THE VALUE OF*/
     /* l_ecm_status IS LATER USED IN THE CALLING PROGRAM TO VERIFY    */
     /* THE STATUS OF PCR/PCO.                                         */
     /* A NON-BLANK VALUE IN ecm_appr_date INDICATES A PCR/PCO TO BE IN*/
     /* 'APPROVED' STAGE. BUT IF ecm_close_date IS ALSO NON-BLANK,THEN */
     /* THE STATUS OF 'CLOSED' SHOULD BE CONSIDERED.                   */

         procedure get_ecm_status:

            define parameter buffer ecm_mstr for ecm_mstr.
            define output parameter l_ecm_status as character no-undo.

            assign l_ecm_status = "".

            if ecm_close_date     <> ? then l_ecm_status = "CLOSED".
            else if ecm_end_date  <> ? then l_ecm_status = "IMPLEMENT".
            else if ecm_eff_date  <> ? then l_ecm_status = "INCORPORATED".
            else if ecm_rel_date  <> ? then l_ecm_status = "RELEASED".
            else if ecm_appr_date <> ? then l_ecm_status = "APPROVED".
            else if (ecm_sub_date <> ? and
            (can-find(first rsu_mstr where
                    rsu_doc_nbr   = ecm_nbr and
                                    rsu_appr_date = rsu_route_date - 1)))
                                       then l_ecm_status = "REROUTED".
            else if ecm_sub_date  <> ? then l_ecm_status = "SUBMITTED".
            else if ecm_sub_date   = ? then l_ecm_status = "UNSUBMITTED".

         end. /* PROCEDURE GET_ECM_STATUS */

/*M120*/ /* ADDED PROCEDURE TO RETURN THE CONVERTED PCO STATUS */

         PROCEDURE get_ecm_status_label:

            define parameter buffer ecm_mstr  for ecm_mstr.
            define input  parameter length    as integer   no-undo.
            define output parameter ecmstatus as character no-undo.

            /* get_ecm_status WILL RETURN THE STATUS OF THE PCO */
            run get_ecm_status (buffer ecm_mstr, output ecmstatus).

            /* get_label_of_ecm_status WILL RETURN LABEL OF THE PCO STATUS */
            run get_label_of_ecm_status (input-output ecmstatus, input length).

         END PROCEDURE. /* PROCEDURE get_status */

/*M120*/ /* ADDED PROCEDURE TO RETURN THE LABEL OF ecmstatus */

         PROCEDURE get_label_of_ecm_status:

            define input-output parameter ecmstatus  as character no-undo.
            define input        parameter length     as integer   no-undo.

            if ecmstatus = "CLOSED"
            then
               ecmstatus = getTermLabel("CLOSED", length).
            else if ecmstatus = "IMPLEMENT"
            then
               ecmstatus = getTermLabel("IMPLEMENT", length).
            else if ecmstatus = "INCORPORATED"
            then
               ecmstatus = getTermLabel("INCORPORATED", length).
            else if ecmstatus = "RELEASED"
            then
               ecmstatus = getTermLabel("RELEASED", length).
            else if ecmstatus = "APPROVED"
            then
               ecmstatus =  getTermLabel("APPROVED", length).
            else if ecmstatus = "REROUTED"
            then
               ecmstatus = getTermLabel("REROUTED", length).
            else if ecmstatus = "SUBMITTED"
            then
               ecmstatus = getTermLabel("SUBMITTED", length).
            else if ecmstatus = "UNSUBMITTED"
            then
               ecmstatus = getTermLabel("UNSUBMITTED", length).

         END PROCEDURE. /* PROCEDURE get_label */


/*M100*/ /* THE FOLLOWING CODE ENSURES THAT AT ANY GIVEN MOMENT OF TIME   */
/*M100*/ /* THERE WILL BE ONLY ONE UNDISTRIBUTED PCO REFERENCING AN ITEM. */
/*M100*/ /* HOWEVER THIS RULE WILL APPLY TO PCOs ONLY. THIS IMPLIES THAT  */
/*M100*/ /* IT IS LEGAL FOR MULTIPLE PCRs TO REFERENCE THE SAME ITEM.     */

/*M100*/ PROCEDURE same_item_multiple_pco:

         /* INPUT PARAMETERS */
         define input parameter  l_part like ecd_det.ecd_part no-undo.

         /* OUTPUT PARAMETERS */
         define output parameter l_ecmnbr     like ecm_mstr.ecm_nbr no-undo.
         define output parameter l_pco_exists like mfc_logical      no-undo.

         /* LOCAL BUFFERS */
         define buffer l_ecddet  for ecd_det.
         define buffer l_ecmmstr for ecm_mstr.


         /* BODY OF THE INTERNAL PROCEDURE */
         l_pco_exists = no.

         for each l_ecddet
            fields (ecd_part ecd_nbr)
            where l_ecddet.ecd_part = l_part
            no-lock,
             each l_ecmmstr
            fields (ecm_nbr ecm_rel_date ecm_end_date ecm_close_date
                    ecm_doc_type)
            where l_ecmmstr.ecm_nbr        = l_ecddet.ecd_nbr
            and   l_ecmmstr.ecm_rel_date   = ?
            and   l_ecmmstr.ecm_end_date   = ?
            and   l_ecmmstr.ecm_close_date = ?
            and   l_ecmmstr.ecm_doc_type   = "PCO"
            no-lock:

               assign
                  l_pco_exists = yes
                  l_ecmnbr     = trim(substring(l_ecmmstr.ecm_nbr,1,8)).

               leave.

         end. /* FOR EACH ecd_det */

/*M100*/ END PROCEDURE.
